package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"wxgin/util"
)

func main() {
	router := gin.Default()

	router.Handle("GET", "/", func(c *gin.Context) {
		fmt.Println("do none!!!")
	})

	router.Handle("GET", "/wx", func(c *gin.Context) {
		signature := c.Query("signature")
		timestamp := c.Query("timestamp")
		nonce := c.Query("nonce")
		echostr := c.Query("echostr")

		fmt.Println("signature", signature)
		fmt.Println("timestamp", timestamp)
		fmt.Println("nonce", nonce)
		fmt.Println("echostr", echostr)

		ok := util.CheckSignature(signature, timestamp, nonce, "coleliedev")
		fmt.Println(ok)

		fmt.Println("Hello A")

		if ok {
			_, err := c.Writer.WriteString(echostr)
			if err != nil {
				log.Println(err)
			}
		}
	})

	log.Fatal(router.Run(":8005"))
}
